473,461 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

get object position and change it?

Hi,

I do not know where should I start to solve this problem.

I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the bottom of my
webpage, I am using position :absolute for the div so everytime when
the div shows, it will "drop down" cause the vertical scroll bar
appears on web browser and the user have to scroll down to see the
whole calendar. I was trying to change the div position (e.g if it is
near the bottom of webbrowser then "drop-up") when the div is showing.

My question is
How can I know its position is near the bottom of web browser? (how can
I know the height of the browser)
How can I change the position of this div?

Thanks for any help and example links.

-rockdale

Sep 7 '06 #1
2 28407
Hey,
I'd be able to help a lot better if I could see the site, so I could
know what you're trying to do. However, I can help you with your
questions.

You can get the position of the object by doing this:
myDiv = document.getElementById('calendarDiv');
divPos = myDiv.style.top;

You can then check it against the size of the browser. In every browser
but IE, window.innerHeight will tell you your window size. So use this
code to get your height

if( typeof(window.innerHeight) == 'number' ) {
//Everything but IE
wHeight = window.innerHeight;
else if( document.documentElement && (
document.documentElement.clientWidth ||
document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
wHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) ) {
//IE 4 compatible
wHeight = document.body.clientHeight;
}

Now that you have your window height, test to see where your div is in
proportion to the middle of the screen.

if (myDiv.style.top (wHeight/2)){
//it is more than halfway down the page, pop it at the bottom
myDiv.style.top = (wHeight-myDiv.style.height) //You may need to play
with this a bit.
} else {
//it is more than halfway up the page, pop it at the top
myDiv.style.top = 0;
}

I hope this helped and I hope it's what you were looking to do. And of
course you'd have to replace the 'calendarDiv' with the id you assigned
your div (give it one if you haven't, and make sure it's unique).
Again, if you have a link, post it and I will take a look to see if I
am assuming things correctly. Have a good one!

~Ben~

ro************@gmail.com wrote:
Hi,

I do not know where should I start to solve this problem.

I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the bottom of my
webpage, I am using position :absolute for the div so everytime when
the div shows, it will "drop down" cause the vertical scroll bar
appears on web browser and the user have to scroll down to see the
whole calendar. I was trying to change the div position (e.g if it is
near the bottom of webbrowser then "drop-up") when the div is showing.

My question is
How can I know its position is near the bottom of web browser? (how can
I know the height of the browser)
How can I change the position of this div?

Thanks for any help and example links.

-rockdale
Sep 7 '06 #2
Thanks for the code sample. I will try it ans let you updated.

Again, thanks
-rockdale

Beni Rose wrote:
Hey,
I'd be able to help a lot better if I could see the site, so I could
know what you're trying to do. However, I can help you with your
questions.

You can get the position of the object by doing this:
myDiv = document.getElementById('calendarDiv');
divPos = myDiv.style.top;

You can then check it against the size of the browser. In every browser
but IE, window.innerHeight will tell you your window size. So use this
code to get your height

if( typeof(window.innerHeight) == 'number' ) {
//Everything but IE
wHeight = window.innerHeight;
else if( document.documentElement && (
document.documentElement.clientWidth ||
document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
wHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) ) {
//IE 4 compatible
wHeight = document.body.clientHeight;
}

Now that you have your window height, test to see where your div is in
proportion to the middle of the screen.

if (myDiv.style.top (wHeight/2)){
//it is more than halfway down the page, pop it at the bottom
myDiv.style.top = (wHeight-myDiv.style.height) //You may need to play
with this a bit.
} else {
//it is more than halfway up the page, pop it at the top
myDiv.style.top = 0;
}

I hope this helped and I hope it's what you were looking to do. And of
course you'd have to replace the 'calendarDiv' with the id you assigned
your div (give it one if you haven't, and make sure it's unique).
Again, if you have a link, post it and I will take a look to see if I
am assuming things correctly. Have a good one!

~Ben~

ro************@gmail.com wrote:
Hi,

I do not know where should I start to solve this problem.

I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the bottom of my
webpage, I am using position :absolute for the div so everytime when
the div shows, it will "drop down" cause the vertical scroll bar
appears on web browser and the user have to scroll down to see the
whole calendar. I was trying to change the div position (e.g if it is
near the bottom of webbrowser then "drop-up") when the div is showing.

My question is
How can I know its position is near the bottom of web browser? (how can
I know the height of the browser)
How can I change the position of this div?

Thanks for any help and example links.

-rockdale
Sep 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
Hi group, Here's a problem I've been trying to solve for the past several weeks. I have the standard WebBrowser object added to a form so it can access websites, and I have it load a default...
3
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle...
3
by: Mr. x | last post by:
Hello, I have simple table <table id = "mytable" ....> .... </table> I want to get the left position of the table. Everything I did getting wrong :
7
by: GfxGuy | last post by:
I've seen this problem posted a million times, but I've read through all of them and can't figure out what I'm doing wrong. Simple example (this is the whole file, no editing): ---------- ...
3
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions...
1
by: D. Yates | last post by:
Hi, I retrieved the employee table from the Pubs database into a single dataset called, dataSet12. I dropped two textbox controls and a datagrid control onto the same form and bound the...
4
by: Jesse Villani | last post by:
I will get this eventually, I have a combobox on a form which is bound to a dataset and displays correct values in the list. When i select a value from the list, i check to see what is the...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
9
by: koschwitz | last post by:
Hi, I hope you guys can help me make this simple application work. I'm trying to create a form displaying 3 circles, which independently change colors 3 times after a random time period has...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.